export const showToast = (data: string) => {
	setTimeout(() => {
		uni.showToast({
			title:data,
			duration: 1500,
			icon:"none",
			image:"",
			mask:false
		})
	},150)
	
}

let loadingCount:number = 0
let loadingTime:any
export const showLoading = (data: string) => {
	if(loadingCount === 0) {
		uni.showLoading({
			title:data,
			mask:true
		})
		// 最长10s自动关闭
		loadingTime = setTimeout(() => {
			if (loadingCount > 0) {
				uni.hideLoading();
			}
		}, 10000);
	}
	loadingCount++
}

export const hideLoading = () => {
	if (loadingCount <= 0) return;
	loadingCount--
	if (loadingCount === 0) {
		loadingTime && clearTimeout(loadingTime)
		const t = setTimeout(() => {
			uni.hideLoading()
			clearTimeout(t)
		}, 200)
	}
}

export const showModal = (data:any) => {
	uni.showModal({
		title:data.title,
		content:data.content,
		confirmColor:'#1769ff'
	})
}

export const confirm = (data:string) => {
	return new Promise((resolve, reject) => {
		uni.showModal({
			title:'温馨提示',
			content:data,
			confirmColor:'#1769ff',
			success:(res:any) => {
				if(res.confirm) {
					resolve(res)
				} else if(res.cancel){
					reject()
				}
			},
		})
	})
	
}